//
//  UsersViewController.m
//  EconomyDemo
//
//  Created by qianfeng01 on 15-7-4.
//  Copyright (c) 2015年 xiangmu. All rights reserved.
//

#import "UsersViewController.h"
#import "IntroViewController.h"
#import "SDImageCache.h"
//#import "UMSocial.h"
@interface UsersViewController ()<UITableViewDataSource,UITableViewDelegate,UIActionSheetDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArray;
}

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation UsersViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self initData];
    [self creatTableView];
}
-(void)initData{
    _dataArray=[[NSMutableArray alloc] initWithObjects:@"版本:2.0",@"联系我们:1791999589@qq.com",@"关于我们",@"清除缓存", nil];
    }
-(void)creatTableView{
    _tableView=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width,self.view.bounds.size.height-64) style:UITableViewStyleGrouped];
    _tableView.delegate=self;
    _tableView.dataSource=self;
    
    UIImageView *imageView=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 200)];
    imageView.image=[UIImage imageNamed:@"start"];
    self.tableView.tableHeaderView=imageView;
    
    
    [self.view addSubview:self.tableView];
    
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID=@"cellID";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell==nil) {
        cell=[[UITableViewCell alloc] init];
    }
    cell.textLabel.text=self.dataArray[indexPath.row];
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    switch (indexPath.row) {
        case 2:
        {
            IntroViewController *controller=[[IntroViewController alloc] init];
            [self.navigationController pushViewController:controller animated:YES];
        }
            break;
        case 3:
        {
            UIActionSheet *sheet=[[UIActionSheet alloc] initWithTitle:[NSString stringWithFormat:@"删除缓存文件:%.6fM",[self getCachesSize]] delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:nil];
            [sheet showInView:self.view];
        }
            break;
        case 4:
        {
//            NSString *text = [NSString stringWithFormat:@"财经周刊"];
//            [UMSocialSnsService presentSnsIconSheetView:self appKey:@"507fcab25270157b37000010"
//      shareText:text shareImage:[UIImage imageNamed: @"account_candou"]shareToSnsNames:@[UMShareToSina,UMShareToSms,UMShareToEmail,UMShareToQQ,UMShareToWechatTimeline]delegate:self];
        }
            break;
        default:
            break;
    }
    
}
-(double)getCachesSize{
    double sdSize=[[SDImageCache sharedImageCache] getSize];
     NSString *myCachePath=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/MyCaches"];
    NSDirectoryEnumerator *enumerator=[[NSFileManager defaultManager] enumeratorAtPath:myCachePath];
    double mySize;
    for (NSString *fileName in enumerator) {
              NSString *filePath=[myCachePath stringByAppendingPathComponent:fileName];
               NSDictionary *dict=[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:nil];
               mySize +=dict.fileSize;
    }
    double totalSize=(mySize+sdSize)/1024/1024;//转化为M
    return totalSize;
    
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==actionSheet.destructiveButtonIndex) {
        [[SDImageCache sharedImageCache] clearMemory];
        [[SDImageCache sharedImageCache] clearDisk];
        NSString *myCachePath=[NSHomeDirectory() stringByAppendingFormat:@"/Library/Caches/MyCaches"];
        [[NSFileManager defaultManager] removeItemAtPath:myCachePath error:nil];
        
    }
}
-(BOOL)isDirectShareInIconActionSheet
{
    return YES;
}

//-(void)didFinishGetUMSocialDataInViewController:(UMSocialResponseEntity *)response
//{
//    //根据`responseCode`得到发送结果,如果分享成功
//    if(response.responseCode == UMSResponseCodeSuccess)
//    {
//        //得到分享到的微博平台名
//        NSLog(@"share to sns name is %@",[[response.data allKeys] objectAtIndex:0]);
//    }
//}



@end
